package com.atguigu.gmall.web.controller;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.item.client.ItemFeignClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;

import java.util.Map;

/**
 * web-all模块所有controller目的渲染静态页模板,所有的控制器都要采用@Controller
 *
 * @author: atguigu
 * @create: 2023-04-22 09:33
 */
@Controller
@SuppressWarnings("all")
public class ItemController {

    @Autowired
    private ItemFeignClient itemFeignClient;

    /**
     * 渲染商品详情页面
     *
     * @param skuId
     * @return
     */
    @GetMapping("/{skuId}.html")
    public String itemHtml(Model model, @PathVariable("skuId") Long skuId) {
        //1.远程调用详情微服务获取渲染详情页面所需 商品所有数据
        Result<Map> result = itemFeignClient.getItemInfo(skuId);
        //2.封装到Model对象中
        model.addAllAttributes(result.getData());
        //3.返回字符串代表渲染静态页模板
        return "/item/item";
    }
}
